home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
MACSHELL
/
MS1
/
SHELL_SO
/
LAUNCH.C
next >
Wrap
Text File
|
1990-04-18
|
4KB
|
167 lines
/*
* MacShell Source File
*
* Copyright (c) 1989, 1990 Suick Bay Technologies. All rights reserved.
*
* P.O. Box 29202
* Mpls, MN 55429
*
* No parts of this software may be reproduced or stored in a
* retrieval system or transmitted in any form, or any means,
* electronic, mechanical, photocopying, recording or otherwise,
* without the prior written permission of Suick Bay Technologies.
*
* Spread the word and not the disk.
*
* SPK 012290 : Initial
*/
#include "system.h"
#include <string.h>
#include <MultiFinder.h>
#include <SegmentLdr.h>
/*
* Error codes returned by MultiFinder
*/
#define MFNoMem1 -10 /* Not enough memory to launch */
#define MFNoMem2 -11 /* Not enough memory to launch */
#define MFUnknown -12 /* Unknown error */
#define MFNoCODE0 -13 /* CODE 0 resource is corrupt */
#define MFNoMem3 -14 /* Not enough memory to launch */
typedef struct
{
char filename[ 32 ]; /* Name of file containing app (Pascal format) */
int16 WD; /* WDRefNum of directory containing app */
int16 MFFlags; /* Flags from SIZE resource */
int32 prefSize; /* Preferred MultiFinder partition size */
int32 minSize; /* Minimum MultiFinder partition size */
} appInfo;
typedef struct /* SIZE resource format */
{
int16 flags;
int32 pref;
int32 min;
} sizeRec, *sizePtr, **sizeHand;
extern int32 DefltStack : 0x322;
/*******************************************************************/
pascal OSErr MFLaunch( char *fname, long partSize, int16 volID,
long SIZEflags, long stacksize)
{
Handle save = AppParmHandle;
AppParmHandle = NULL;
asm {
UNLK A6
MOVE.L (A7)+,A2
MOVE.W #16,-(SP)
_OSDispatch
JMP (A2)
}
AppParmHandle = save;
}
/*******************************************************************/
OSErr GetAppInfo( char *name, int16 WDRefNum, appInfo *infoStruct )
{
int16 appFile;
sizeHand sHand;
CopyStr( name, infoStruct->filename );
infoStruct->WD = WDRefNum;
SetResLoad( FALSE );
appFile = OpenRFPerm( infoStruct->filename, WDRefNum, fsRdPerm );
SetResLoad( TRUE );
if( appFile == -1 )
return ResError();
if( sHand = (sizeHand) Get1Resource('SIZE', 0 ) )
sHand = (sizeHand) Get1Resource('SIZE', -1);
if( sHand == NULL )
{
/*
* App has no size resource, attemp an old application
*/
infoStruct->MFFlags = 0;
infoStruct->prefSize = (512L*1024L);
if((ROM85 & 0xC000) == 0)
infoStruct->prefSize += (int32) 0x8000;
infoStruct->minSize = (384L*1024L);
}
else
{
infoStruct->MFFlags = (*sHand)->flags;
infoStruct->prefSize = (*sHand)->pref;
if((ROM85 & 0xC000) == 0)
infoStruct->prefSize += (int32) 0x8000;
infoStruct->minSize = (*sHand)->min;
}
CloseResFile( appFile );
return( noErr );
}
/*******************************************************************/
OSErr LaunchApp( appInfo *info )
{
OSErr err;
err = MFLaunch(info->filename, info->prefSize+DefltStack-0x2000,
info->WD, info->MFFlags, DefltStack);
if (err == MFNoMem1 || err == MFNoMem2 || err == MFNoMem3 )
err = MFLaunch( info->filename, info->minSize+DefltStack-0x2000,
info->WD, info->MFFlags, DefltStack );
if (err > 0)
err = noErr;
return err;
}
/*******************************************************************/
Boolean CanLaunch()
{
int32 t1, t2;
t1 = NGetTrapAddress( 0xA88F, ToolTrap );
t2 = NGetTrapAddress( UNIMPLEMENTED_TRAP_NUM, ToolTrap );
return( t1 != t2 );
}
OSErr DoLaunch( char *str, int vRefNum, int32 dirID )
{
appInfo info;
int16 wdRefNum;
OSErr err;
err = OpenWD( vRefNum, dirID, 'sBAY', &wdRefNum );
if( !err )
{
err = GetAppInfo( str, wdRefNum, &info );
if( !err )
err = LaunchApp( &info );
}
return( err );
}